/**
 * 
 */
package megamek.common.actions;

import java.util.ArrayList;

import junit.framework.TestCase;
import megamek.common.Aero;
import megamek.common.Entity;
import megamek.common.EquipmentType;
import megamek.common.Game;
import megamek.common.IAimingModes;
import megamek.common.IGame;
import megamek.common.Mounted;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * Test case for the WeaponAttackAction class.
 * 
 * @author Odessa
 * 
 */
public class WeaponAttackActionTest extends TestCase
{
	private WeaponAttackAction attack1;
	private WeaponAttackAction attack2;
	private IGame game;

	private int num;
	private int entityId;
	private int targetId;
	private int weaponId;
	private int targetType;



	/**
	 * Sets up the test case.
	 * 
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception
	{
		entityId = 1;
		targetId = 2;
		weaponId = 3;
		targetType = 4;
		num = 5;

		attack1 = new WeaponAttackAction(entityId, targetId, weaponId);
		attack2 = new WeaponAttackAction(entityId, targetType, targetId,
				weaponId);
		game = new Game();
	}



	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception
	{
	}



	/**
	 * Test method for
	 * {@link megamek.common.actions.WeaponAttackAction#getWeaponId()}.
	 */
	@Test
	public void testGetWeaponId()
	{
		assertEquals(weaponId, attack1.getWeaponId());
		assertEquals(weaponId, attack2.getWeaponId());
	}



	/**
	 * Test method for
	 * {@link megamek.common.actions.WeaponAttackAction#getAmmoId()}.
	 */
	@Test
	public void testGetAmmoId()
	{
		assertEquals(-1, attack1.getAmmoId());
		assertEquals(-1, attack2.getAmmoId());
	}



	/**
	 * Test method for
	 * {@link megamek.common.actions.WeaponAttackAction#getAimedLocation()}.
	 */
	@Test
	public void testGetAimedLocation()
	{
		int x = Entity.LOC_NONE;
		assertEquals(x, attack1.getAimedLocation());
		assertEquals(x, attack2.getAimedLocation());
	}



	/**
	 * Test method for
	 * {@link megamek.common.actions.WeaponAttackAction#getAimingMode()}.
	 */
	@Test
	public void testGetAimingMode()
	{
		int x = IAimingModes.AIM_MODE_NONE;
		assertEquals(x, attack1.getAimingMode());
		assertEquals(x, attack2.getAimingMode());
	}



	/**
	 * Test method for
	 * {@link megamek.common.actions.WeaponAttackAction#setWeaponId(int)}.
	 */
	@Test
	public void testSetWeaponId()
	{
		attack1.setWeaponId(num);
		attack2.setWeaponId(num);

		assertEquals(5, attack1.getWeaponId());
		assertEquals(5, attack2.getWeaponId());
	}



	/**
	 * Test method for
	 * {@link megamek.common.actions.WeaponAttackAction#setAmmoId(int)}.
	 */
	@Test
	public void testSetAmmoId()
	{
		attack1.setAmmoId(num);
		attack2.setAmmoId(num);

		assertEquals(5, attack1.getAmmoId());
		assertEquals(5, attack2.getAmmoId());
	}



	/**
	 * Test method for
	 * {@link megamek.common.actions.WeaponAttackAction#setAimedLocation(int)}.
	 */
	@Test
	public void testSetAimedLocation()
	{
		attack1.setAimedLocation(num);
		assertEquals(5, attack1.getAimedLocation());
	}



	/**
	 * Test method for
	 * {@link megamek.common.actions.WeaponAttackAction#setAimingMode(int)}.
	 */
	@Test
	public void testSetAimingMode()
	{
		attack1.setAimingMode(num);
		assertEquals(5, attack1.getAimingMode());
	}



	/**
	 * Test method for
	 * {@link megamek.common.actions.WeaponAttackAction#addCounterEquipment(megamek.common.Mounted)}
	 * .
	 */
	@Test
	public void testAddCounterEquipment()
	{
		Mounted m = new Mounted(new Aero(), new EquipmentType());
		attack1.addCounterEquipment(m);

		ArrayList<Mounted> mArr = new ArrayList<Mounted>();
		mArr.add(m);

		assertEquals(mArr, attack1.getCounterEquipment());
	}



	/**
	 * Test method for
	 * {@link megamek.common.actions.WeaponAttackAction#setOtherAttackInfo(int)}
	 * .
	 */
	@Test
	public void testSetOtherAttackInfo()
	{
		attack1.setOtherAttackInfo(num);
		assertEquals(5, attack1.getOtherAttackInfo());
	}



	/**
	 * Test method for
	 * {@link megamek.common.actions.WeaponAttackAction#getOtherAttackInfo()}.
	 */
	@Test
	public void testGetOtherAttackInfo()
	{
		assertEquals(-1, attack1.getOtherAttackInfo());
	}



	/**
	 * Test method for
	 * {@link megamek.common.actions.WeaponAttackAction#toHit(megamek.common.IGame)}
	 * .
	 */
	@Test
	public void testToHitIGame_Null()
	{
		fail("Not yet implemented");
		// attack2.setSwarmingMissiles(true);
		// attack2.setNemesisConfused(true);
		// attack2.setTargetId(1);
		// ToHitData thd = new
		// ToHitData(TargetRoll.AUTOMATIC_FAIL,"swarm target out of range");

		// ToHitData attackHD = attack1.toHit(game);
		// System.out.println(attackHD);
		// assertEquals(thd.getHitTable(), attackHD.getHitTable());
		// assertEquals(thd.getSideTable(), attackHD.getSideTable());
	}



	/**
	 * Test method for
	 * {@link megamek.common.actions.WeaponAttackAction#toHit(megamek.common.IGame, int, megamek.common.Targetable, int)}
	 * .
	 */
	@Test
	public void testToHitIGameIntTargetableInt()
	{
		fail("Not yet implemented");
		// attack1
		// attack2
	}



	/**
	 * Test method for
	 * {@link megamek.common.actions.WeaponAttackAction#toHit(megamek.common.IGame, int, megamek.common.Targetable, int, int, int)}
	 * .
	 */
	@Test
	public void testToHitIGameIntTargetableIntIntInt()
	{
		fail("Not yet implemented");

		/*
		 * WeaponAttackAction.toHit(game, 2, game.getTarget(1, 2), weaponId,
		 * attack2.getAimedLocation(), attack2.getAimingMode());
		 */

	}



	/**
	 * Test method for
	 * {@link megamek.common.actions.WeaponAttackAction#setNemesisConfused(boolean)}
	 * .
	 */
	@Test
	public void testSetNemesisConfused()
	{
		attack1.setNemesisConfused(true);
		assertTrue(attack1.isNemesisConfused());
	}



	/**
	 * Test method for
	 * {@link megamek.common.actions.WeaponAttackAction#setSwarmingMissiles(boolean)}
	 * .
	 */
	@Test
	public void testSetSwarmingMissiles()
	{
		attack1.setSwarmingMissiles(true);
		assertTrue(attack1.isSwarmingMissiles());
	}



	/**
	 * Test method for
	 * {@link megamek.common.actions.WeaponAttackAction#getSwarmMissiles()}.
	 */
	@Test
	public void testGetSwarmMissiles()
	{
		assertEquals(0, attack1.getSwarmMissiles());
	}



	/**
	 * Test method for
	 * {@link megamek.common.actions.WeaponAttackAction#setSwarmMissiles(int)}.
	 */
	@Test
	public void testSetSwarmMissiles()
	{
		attack1.setSwarmMissiles(num);
		assertEquals(5, attack1.getSwarmMissiles());
	}



	/**
	 * Test method for
	 * {@link megamek.common.actions.WeaponAttackAction#getBombPayload()}.
	 */
	@Test
	public void testGetBombPayload()
	{
		assertEquals(15, attack1.getBombPayload().length);
	}



	/**
	 * Test method for
	 * {@link megamek.common.actions.WeaponAttackAction#setBombPayload(int[])}.
	 */
	@Test
	public void testSetBombPayload()
	{
		int[] nums = { 1, 2, 3, 4, 5 };
		attack1.setBombPayload(nums);
		int[] exp = attack1.getBombPayload();

		String numbers = "", expected = "";

		for (int i : nums)
			numbers += i + ", ";
		for (int i : exp)
			expected += i + ", ";

		assertTrue("Expected 'numbers' and 'expected' to be equal." +
				"\n  'numbers'        = " + numbers + "\n  'expected' = " +
				expected, expected.equals(numbers));
	}
}
